//
//  AppleScriptPrediction.m
//  Pennyworth
//
//  Created by Chris Karr on 2/19/08.
//  Copyright 2008 Chris J. Karr. All rights reserved.
//

#import "AppleScriptPrediction.h"

@implementation AppleScriptPrediction

- (NSScriptObjectSpecifier *) objectSpecifier 
{
	NSArray * predictions = [[NSApp delegate] valueForKey:@"predictions"];

	NSUInteger index = NSNotFound;
	
	NSUInteger i = 0;
	for (i = 0; i < [predictions count] && index == NSNotFound; i++)
	{
		AppleScriptPrediction * prediction = [predictions objectAtIndex:i];
		
		if ([[prediction name] isEqualToString:[self name]])
			index = i;
	}
	
    if (index != NSNotFound) 
	{
		NSScriptObjectSpecifier * containerRef = [NSApp objectSpecifier];

        return [[[NSIndexSpecifier alloc] initWithContainerClassDescription:[containerRef keyClassDescription] 
			containerSpecifier:containerRef key:@"predictions" index:index] autorelease];
    }
	else
        return nil;
}

@end
